home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / WINGs / wmenuitem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-20  |  4.3 KB  |  297 lines

  1.  
  2.  
  3.  
  4.  
  5. #include "WINGsP.h"
  6.  
  7.  
  8.  
  9. typedef struct W_MenuItem {
  10.     char *title;
  11.  
  12.     WMPixmap *image;
  13.  
  14.     char *shortcutKey;
  15.     int shortcutModifierMask;
  16.  
  17.     WMAction *action;
  18.     void *data;
  19.  
  20.     struct W_Menu *submenu;
  21.  
  22.     void *object;
  23.     
  24.     WMPixmap *onStateImage;
  25.     WMPixmap *offStateImage;
  26.     WMPixmap *mixedStateImage;
  27.  
  28.     struct {
  29.     unsigned enabled:1;
  30.     unsigned state:2;
  31.     } flags;
  32. } MenuItem;
  33.  
  34.  
  35.  
  36.  
  37.  
  38. WMMenuItem*
  39. WMGetSeparatorMenuItem(void)
  40. {
  41.     return NULL;
  42. }
  43.  
  44.  
  45. Bool
  46. WMMenuItemIsSeparator(WMMenuItem *item)
  47. {
  48.     return False;
  49. }
  50.  
  51.  
  52. WMMenuItem*
  53. WMCreateMenuItem(void)
  54. {
  55.     WMMenuItem *item;
  56.     
  57.     item = wmalloc(sizeof(WMMenuItem));
  58.     memset(item, 0, sizeof(WMMenuItem));
  59.  
  60.     item->flags.enabled = 1;
  61.     
  62.     return item;
  63. }
  64.  
  65.  
  66. void
  67. WMDestroyMenuItem(WMMenuItem *item)
  68. {
  69.     if (item->title)
  70.     free(item->title);
  71.  
  72.     if (item->image)
  73.     WMReleasePixmap(item->image);
  74.  
  75.     if (item->shortcutKey)
  76.     free(item->shortcutKey);
  77.     
  78.     if (item->onStateImage)
  79.     WMReleasePixmap(item->onStateImage);
  80.     
  81.     if (item->offStateImage)
  82.     WMReleasePixmap(item->offStateImage);
  83.     
  84.     if (item->mixedStateImage)
  85.     WMReleasePixmap(item->mixedStateImage);
  86. }
  87.  
  88.  
  89. Bool
  90. WMGetMenuItemEnabled(WMMenuItem *item)
  91. {
  92.     return item->flags.enabled;
  93. }
  94.  
  95.  
  96. void
  97. WMSetMenuItemEnabled(WMMenuItem *item, Bool flag)
  98. {
  99.     item->flags.enabled = flag;
  100. }
  101.  
  102.  
  103. char*
  104. WMGetMenuItemShortcut(WMMenuItem *item)
  105. {
  106.     return item->shortcutKey;
  107. }
  108.  
  109.  
  110. unsigned
  111. WMGetMenuItemShortcutModifierMask(WMMenuItem *item)
  112. {
  113.     return item->shortcutModifierMask;
  114. }
  115.  
  116.  
  117.  
  118. void
  119. WMSetMenuItemShortcut(WMMenuItem *item, char *shortcut)
  120. {
  121.     if (item->shortcutKey)
  122.     wfree(item->shortcutKey);
  123.  
  124.     item->shortcutKey = wstrdup(shortcut);
  125. }
  126.  
  127.  
  128. void
  129. WMSetMenuItemShortcutModifierMask(WMMenuItem *item, unsigned mask)
  130. {
  131.     item->shortcutModifierMask = mask;
  132. }
  133.  
  134.  
  135. void*
  136. WMGetMenuItemRepresentedObject(WMMenuItem *item)
  137. {
  138.     return item->object;
  139. }
  140.  
  141.  
  142. void
  143. WMSetMenuItemRepresentedObject(WMMenuItem *item, void *object)
  144. {
  145.     item->object = object;
  146. }
  147.  
  148.  
  149. void
  150. WMSetMenuItemAction(WMMenuItem *item, WMAction *action, void *data)
  151. {
  152.     item->action = action;
  153.     item->data = data;
  154. }
  155.  
  156.  
  157. WMAction*
  158. WMGetMenuItemAction(WMMenuItem *item)
  159. {
  160.     return item->action;
  161. }
  162.  
  163.  
  164. void*
  165. WMGetMenuItemData(WMMenuItem *item)
  166. {
  167.     return item->data;
  168. }
  169.  
  170.  
  171. void
  172. WMSetMenuItemTitle(WMMenuItem *item, char *title)
  173. {
  174.     if (item->title)
  175.     wfree(item->title);
  176.     
  177.     if (title)
  178.     item->title = wstrdup(title);
  179.     else
  180.     item->title = NULL;
  181. }
  182.  
  183.  
  184. char*
  185. WMGetMenuItemTitle(WMMenuItem *item)
  186. {
  187.     return item->title;
  188. }
  189.  
  190.  
  191. void
  192. WMSetMenuItemState(WMMenuItem *item, int state)
  193. {
  194.     item->flags.state = state;
  195. }
  196.  
  197.  
  198. int
  199. WMGetMenuItemState(WMMenuItem *item)
  200. {
  201.     return item->flags.state;
  202. }
  203.  
  204.  
  205. void
  206. WMSetMenuItemPixmap(WMMenuItem *item, WMPixmap *pixmap)
  207. {
  208.     if (item->image)
  209.     WMReleasePixmap(item->image);
  210.  
  211.     item->image = WMRetainPixmap(pixmap);
  212. }
  213.  
  214.  
  215. WMPixmap*
  216. WMGetMenuItemPixmap(WMMenuItem *item)
  217. {
  218.     return item->image;
  219. }
  220.  
  221.  
  222. void
  223. WMSetMenuItemOnStatePixmap(WMMenuItem *item, WMPixmap *pixmap)
  224. {
  225.     if (item->onStateImage)
  226.     WMReleasePixmap(item->onStateImage);
  227.     
  228.     item->onStateImage = WMRetainPixmap(pixmap);
  229. }
  230.  
  231.  
  232. WMPixmap*
  233. WMGetMenuItemOnStatePixmap(WMMenuItem *item)
  234. {
  235.     return item->onStateImage;
  236. }
  237.  
  238.  
  239. void
  240. WMSetMenuItemOffStatePixmap(WMMenuItem *item, WMPixmap *pixmap)
  241. {
  242.     if (item->offStateImage)
  243.     WMReleasePixmap(item->offStateImage);
  244.     
  245.     item->offStateImage = WMRetainPixmap(pixmap);
  246. }
  247.  
  248.  
  249. WMPixmap*
  250. WMGetMenuItemOffStatePixmap(WMMenuItem *item)
  251. {
  252.     return item->offStateImage;
  253. }
  254.  
  255.  
  256.  
  257. void
  258. WMSetMenuItemMixedStatePixmap(WMMenuItem *item, WMPixmap *pixmap)
  259. {
  260.     if (item->mixedStateImage)
  261.     WMReleasePixmap(item->mixedStateImage);
  262.     
  263.     item->mixedStateImage = WMRetainPixmap(pixmap);
  264. }
  265.  
  266.  
  267. WMPixmap*
  268. WMGetMenuItemMixedStatePixmap(WMMenuItem *item)
  269. {
  270.     return item->mixedStateImage;
  271. }
  272.  
  273.  
  274. /*
  275. void
  276. WMSetMenuItemSubmenu(WMMenuItem *item, WMMenu *submenu)
  277. {
  278.     item->submenu = submenu;
  279. }
  280.  
  281.  
  282. WMMenu*
  283. WMGetMenuItemSubmenu(WMMenuItem *item)
  284. {
  285.     return item->submenu;
  286. }
  287.  
  288.  
  289.  
  290. Bool
  291. WMGetMenuItemHasSubmenu(WMMenuItem *item)
  292. {
  293.     return item->submenu != NULL;
  294. }
  295.  
  296. */
  297.